package com.joysuch.wwyt.bp.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joysuch.wwyt.bp.bean.investigate.TaskSummarySearchBean;
import com.joysuch.wwyt.bp.bean.investigate.vo.AppInvestigateSummaryVo;
import com.joysuch.wwyt.bp.entity.bean.RecordSearchBean;
import com.joysuch.wwyt.bp.entity.dto.BpInvestigateTaskSummaryDto;
import com.joysuch.wwyt.bp.service.BpInvestigateTaskSummaryService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zr
 * @since 2021-09-16
 */
@RestController
@RequestMapping("/bp/bp-investigate-task")
@Api(tags = "排查任务和记录")
public class BpInvestigateTaskSummaryController {

    @Autowired
    private BpInvestigateTaskSummaryService bpInvestigateTaskSummaryService;

    @RequestMapping("/get-today-summary-page")
    @ApiOperation("分页查询今日任务汇总")
    public ResultBean findTodaySummaryPaging(@RequestBody TaskSummarySearchBean bean) {
        IPage<BpInvestigateTaskSummaryDto> page = bpInvestigateTaskSummaryService.findTodaySummaryPaging(bean);
        return ResultBean.pageData(page.getRecords(),page.getTotal());
    }

    @RequestMapping("/get-today-summary-page-app")
    @ApiOperation("分页查询今日任务汇总-App")
    public ResultBean findTodaySummaryPagingApp(@RequestBody TaskSummarySearchBean bean) {
        IPage<AppInvestigateSummaryVo> page = bpInvestigateTaskSummaryService.findTodaySummaryPagingApp(bean);
        return ResultBean.pageData(page.getRecords(),page.getTotal());
    }


    @RequestMapping("/findRecordBySummaryId")
    @ApiOperation("获取单条记录")
    public ResultBean findRecordBySummaryId(Long summaryId) {
        return ResultBean.success(bpInvestigateTaskSummaryService.findRecordBySummaryId(summaryId));
    }


    @RequestMapping("/findRecordSummaryByPaging")
    @ApiOperation("分页查询排查记录的汇总")
    public ResultBean findRecordSummaryByPaging(@RequestBody TaskSummarySearchBean bean) {
        return bpInvestigateTaskSummaryService.findRecordSummaryByPaging(bean, true);
    }


    @RequestMapping("/find-today-record-summary-paging")
    @ApiOperation("分页查询今日记录汇总")
    public ResultBean findTodayRecordSummaryByPaging(@RequestBody TaskSummarySearchBean bean) {
        return bpInvestigateTaskSummaryService.findRecordSummaryByPaging(bean, false);
    }

    @RequestMapping("/get-history-summary-page")
    @ApiOperation("分页查询历史记录汇总")
    public ResultBean getHistorySummaryPage(@RequestBody TaskSummarySearchBean bean) {
        Page page = bpInvestigateTaskSummaryService.findHistorySummaryPage(bean);
        return ResultBean.pageData(page.getRecords(), page.getTotal());
    }

    @GetMapping("/get-history-record-page")
    @ApiModelProperty("通过任务汇总获取任务(以任务完成时间范围做查询)")
    @RequiresPermissions("bp:bp-investigate-task:record")
    public ResultBean getHistoryRecordPage(RecordSearchBean recordSearchBean) {
        return bpInvestigateTaskSummaryService.getHistoryRecordPage(recordSearchBean);
    }

    @PostMapping("/deleteTaskAndRecordById")
    @ApiOperation("根据id删除任务记录的汇总")
    @RequiresPermissions("bp:bp-investigate-task:delete")
    public ResultBean deleteTaskSummaryById(Long summaryId) {
        bpInvestigateTaskSummaryService.deleteSummaryById(summaryId);
        return ResultBean.defaultSuccessResult(); 
    }


    @GetMapping("/getRecordByTaskSummary")
    @ApiModelProperty("通过任务汇总获取任务(以任务的时间范围做查询)")
    @RequiresPermissions("bp:bp-investigate-task:record")
    public ResultBean getRecordByTaskSummary(RecordSearchBean recordSearchBean) {
        return bpInvestigateTaskSummaryService.getRecordByTaskSummaryId(recordSearchBean);
    }

    @GetMapping("/getSubscript")
    @ApiModelProperty("app任务列表角标")
    public ResultBean getSubscript() {
        return ResultBean.success(bpInvestigateTaskSummaryService.getSubscript());
    }

    @GetMapping("/getAppSubTimeTask")
    @ApiModelProperty("app获取今日排查任务:按时间分割")
    public ResultBean getAppSubTimeTask(RecordSearchBean recordSearchBean) {
        return ResultBean.success(bpInvestigateTaskSummaryService.getAppSubTimeTask(recordSearchBean));
    }

    @PostMapping("/get-task-by-ids")
    @ApiModelProperty("app获取任务详情")
    public ResultBean getTaskIdsById(@RequestBody List<Long> taskIds) {
        return ResultBean.success(bpInvestigateTaskSummaryService.getTaskIdsById(taskIds));
    }

    @GetMapping("getRiskPoint-Snapshot")
    @ApiModelProperty("隐患排查地图快照")
    public ResultBean getRiskPointSnapshot(RecordSearchBean recordSearchBean) {
        return ResultBean.success(bpInvestigateTaskSummaryService.getRiskPointSnapshot(recordSearchBean));
    }

    @RequestMapping("/getSummaryCount")
    @ApiModelProperty("获取任务和记录的条数汇总")
    public ResultBean getSummaryCount(@RequestBody TaskSummarySearchBean bean) {
        Map<String, Long> summaryCount = bpInvestigateTaskSummaryService.getTaskSummaryCount(bean);
        return ResultBean.success(summaryCount);
    }

    @GetMapping("/get-nfc-task-group-app")
    @ApiModelProperty("获取NFC点位关联任务")
    public ResultBean getNfcTaskGroupApp(String code) {
        return ResultBean.success(bpInvestigateTaskSummaryService.getNfcTaskGroupApp(code));
    }

    @GetMapping("/get-qrcode-task-group-app")
    @ApiModelProperty("获取NFC点位关联任务")
    public ResultBean getQrCodeTaskGroupApp(String code) {
        return ResultBean.success(bpInvestigateTaskSummaryService.getQrCodeTaskGroupApp(code));
    }

    @GetMapping("/test/snowID")
    @ApiModelProperty("雪花ID生成测试")
    public ResultBean testSnowID(int count) {
        return ResultBean.success(bpInvestigateTaskSummaryService.moveDataTest(count));
    }
}

